/**
 * 注册属性观察者
 * @desc 监视属性值变化
 */
export function RegPropertyOberver(target: any, key: string) {
    let oldValue = target[key];
    Reflect.defineProperty(target, key, {
        get() {
            return oldValue;
        },
        set(newValue: any) {
            if (oldValue !== newValue) {
                if (this["onChanged"]) {
                    this["onChanged"](key, oldValue, newValue);
                }
                oldValue = newValue;
            }
        },
    });
}

/**
 * 数据类映射表
 */
export const DataClassMap: Map<string, any> = new Map();

/**
 * 注册数据类
 * @param 类名
 */
export function RegDataClass(className: string) {
    return (constructor: Function) => {
        if (DataClassMap.has(className)) {
            console.error(`RegDataClass : ${className} is repeated !`);
        }
        DataClassMap.set(className, constructor);
    };
}
